<?php defined('SYSPATH') or die('No direct script access.');
/**
 * Default controller.
 */
class Customer_Controller extends Template_Controller 
{
	public function __construct()
	{
		parent::__construct();
		
		// Add the menu to the template
		$this->template->menu = new View('menu');
		$this->template->content = '';
	}
	
	public function index()
	{
		self::lists(1);
	}

	public function lists($page_no, $type='normal')
	{
		$page_size = 20;
	    $model = new Customer_Model();
		
		$where = $type=='normal' ? "type='normal'" : "type<>'normal'";
		
		$this->pagination = new Pagination(array(
	        'base_url'    => 'customer/lists/', 
	        'uri_segment' => 3, 
			'items_per_page' => $page_size, 
	        'total_items' => $model->select('COUNT(*) AS records_found')->where($where)->find()->records_found
	    ));
	 
		$table = new View('customer/lists');
		$table->customer_type = $type;
		$table->datas = $model->where($where)->limit($page_size, (($page_no - 1) * $page_size))->find_all();
		//$table->datas = $model->find_all();
		
		$this->template->content = $table->render();
	}
	
	public function setprove($customer_id, $flag_prove)
	{
		$model = new Customer_Model($customer_id);
		$model->flag_prove = $flag_prove;
		$model->save();
		
		url::redirect($_SERVER['HTTP_REFERER']);
	}
}